<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./js/vue.js"></script>
    <style>
        #mydiv{
            width: 300px;
            height: 400px;
            border:1px solid black;
            background-image: url("./img/loading.gif");
            background-repeat: no-repeat;
            background-position: center;
        }
    </style>
</head>
<body>
    <div id="app">
        <div v-div-preload="imgSrc" id="mydiv"></div> 
    </div>
</body>
<script>
    Vue.directive("divPreload",function(el,binding){
        console.log(el,binding);
        var imgDom=new Image();
        imgDom.src=binding.value;
        imgDom.onload=function(){
            el.style.backgroundImage="url("+binding.value+")";
            el.style.backgroundSize="100% 100%";
        }
    });

    new Vue({
        el:"#app",
        data:{
            imgSrc:"http://ps3.tgbus.com/uploadfiles/201101/20110104102301111.jpg"
        }
    });
</script>
</html>